package com.tenbit.pdt.ctl;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.tenbit.com.vo.ErrorMsgVO;
import com.tenbit.emp.vo.EMP1000VO;
import com.tenbit.pdt.svc.PDT1000SVCImpl;
import com.tenbit.pdt.vo.ItemInfoVO;
import com.tenbit.pdt.vo.ProductInfoVO;
import com.tenbit.pdt.vo.ResultVO;
import com.tobesoft.platform.PlatformRequest;
import com.tobesoft.platform.PlatformResponse;
import com.tobesoft.platform.data.ColumnInfo;
import com.tobesoft.platform.data.Dataset;
import com.tobesoft.platform.data.DatasetList;
import com.tobesoft.platform.data.VariableList;

@Controller
public class PDT1000CTL {
	@Autowired
	private PDT1000SVCImpl pdt1000svcImpl;
	private Logger log=Logger.getLogger(this.getClass());
	
	public String doChgCalendarForm(String cal){
		String chgCal=null;
		
		if(cal.equals("")){
			chgCal="";
		}else{
			chgCal=cal.substring(0, 4)+"-"+cal.substring(4,6)+"-"+cal.substring(6);
			
		}
		
		return chgCal;
		
	}
	
	public Map<String, String> doRestoreView(HttpServletRequest request,MultipartFile file){
		//복원
		Map<String, String> returnMap=new HashMap<String, String>();
		
		returnMap.put("EMPLOYEE_ID",request.getParameter("employeeName"));
		returnMap.put("NAME",request.getParameter("name"));
		returnMap.put("DEPT_NAME",request.getParameter("dept_code"));
		returnMap.put("PRODUCT_CODE",request.getParameter("productCode"));
		returnMap.put("PRODUCT_NAME",request.getParameter("productName"));
		returnMap.put("ITEM_CODE",request.getParameter("itemCode"));
		returnMap.put("CATEGORY_NAME",request.getParameter("category"));
		returnMap.put("MANUFACTURE_CODE",request.getParameter("manufactureCode"));
		returnMap.put("PRODUCT_NUM",request.getParameter("productNum"));
		returnMap.put("STANDARD", request.getParameter("standard"));
		returnMap.put("UNIT_CODE",request.getParameter("unitCode"));
		returnMap.put("UNIT_PRICE",request.getParameter("unitPrice"));
		log.debug("doRestoreView"+file.getOriginalFilename());
		returnMap.put("FILENAME",file.getOriginalFilename());
		
		return returnMap;
	}
	@RequestMapping("/delPDTInfo.do")
	public void delPDTInfo(HttpServletRequest request, HttpServletResponse response){
			
		log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
                + "=======");

	     PlatformRequest pReq = null;
	     PlatformResponse pRes = null;
	     
	     try {
	          pReq = new PlatformRequest(request, "utf-8");
	          pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
	          pReq.receiveData();
	         
	     } catch (IOException e1) {
	         
	          e1.printStackTrace();
	     }
	     VariableList in_vl = new VariableList();
         VariableList out_vl = new VariableList();
         DatasetList  out_dl = new DatasetList();
	    
	     in_vl = pReq.getVariableList();
	     
	     //get
	     String productNum = in_vl.getValueAsString("productNum");    
	     //String in_var = request.getParameter("in_var");
	    
	     //TODO: logic
	     ProductInfoVO productInfoVO = new ProductInfoVO();
	     productInfoVO.setProductNum(productNum);
	     
	     pdt1000svcImpl.delProductInfo(productInfoVO);
	
	     //out.clearBuffer();
	     out_vl.add("ErrorCode", "0");
	     out_vl.add("ErrorMsg", "삭제가 되었습니다.");
	     try {
	          pRes.sendData(out_vl, out_dl);
	         
	     } catch (IOException e) {
	         
	          e.printStackTrace();
	     }
	    
	     log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
	                + "=======");
	}
	@RequestMapping("/setPDTInfo.do")
	public void setPDTInfo(HttpServletRequest request, HttpServletResponse response){
		log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

		PlatformRequest pReq = null;
		PlatformResponse pRes = null;
		
		try {
			pReq = new PlatformRequest(request, "utf-8");
			pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
			pReq.receiveData();
			
		} catch (IOException e1) {
			
			e1.printStackTrace();
		}
		VariableList in_vl = new VariableList();
		VariableList out_vl = new VariableList();
		DatasetList  in_dl = new DatasetList();
		DatasetList  out_dl = new DatasetList();
		
		in_vl = pReq.getVariableList();
		in_dl = pReq.getDatasetList();
		
		ErrorMsgVO errmMsgVO = pdt1000svcImpl.doValidateCRUD(null, in_dl);
				
		if( errmMsgVO.isErrExist() ){
			out_vl.addStr("ErrorCode", "-1");
			out_vl.addStr("ErrorMsg", errmMsgVO.getErrMsg());
			
			try {
				pRes.sendData(out_vl, out_dl);
				return;
				
			} catch (IOException e) {
				
				e.printStackTrace();
			}
		}
		//get
		Dataset dsData = in_dl.getDataset("setData");
		Dataset dsImg = in_dl.getDataset("imgData");
		
		//TODO: logic
		upload(dsImg);
		ProductInfoVO vo = dataSetToBean(dsData);
		log.debug(dsImg.getColumnAsString(0, "name"));
		
		vo.setFilename(dsImg.getColumnAsString(0, "name"));
		vo.setProductNum(dsData.getColumnAsString(0, "productNum"));
		pdt1000svcImpl.setProductInfo(vo);
		
		//out.clearBuffer();
		out_vl.addStr("ErrorCode", "0");
		out_vl.addStr("ErrorMsg", "수정이 성공되었습니다.");
		try {
			pRes.sendData(out_vl, out_dl);
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");
	}
	
	@RequestMapping("/doDownLoad.do")
	public ModelAndView doDownLoad(@RequestParam("fileName") String fileName){
		log.debug("doDownLoad"+fileName);
		String path="C:\\TB\\WORKSHOP\\workspace\\tbworkshop\\WebContent\\upload\\";
		File file=new File(path+fileName);
		return new ModelAndView("download","downloadFile",file);
	}
	
	@RequestMapping("/doPDTInsView.do")
	public void doPDTInsView(HttpServletRequest request, HttpServletResponse response){
		
		
		 log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
                + "=======");

	     PlatformRequest pReq = null;
	    
	     try {
	          pReq = new PlatformRequest(request, "utf-8");
	          pReq.receiveData();
	         
	     } catch (IOException e1) {
	         
	          e1.printStackTrace();
	     }
	     VariableList in_vl = new VariableList();
	     VariableList out_vl = new VariableList();
	     DatasetList  in_dl = new DatasetList();
	     DatasetList  out_dl = new DatasetList();
	    
	     in_vl = pReq.getVariableList();
	     in_dl = pReq.getDatasetList();
	              
	     //get
	     Dataset dsInput = in_dl.getDataset("input");
	     String productNum = in_vl.getValueAsString("productNum");    
	     //String in_var = request.getParameter("in_var");
	    
	     //TODO: logic
	     Map<String, Object> pdtInfo = pdt1000svcImpl.getProductInfo(productNum);
	     
	     //dataset 설정
	     Dataset dsOutput = new Dataset("output");
	     Dataset dsImg = new Dataset("imgData");
	     
	     dsOutput.addColumn("empId",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("empName",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("deptName",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("productCode",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("productName",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("itemCode",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("category",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("manufactureCode",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("productNum",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("standard",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("unitCode",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("unitPrice",ColumnInfo.CY_COLINFO_STRING, 20);
	     dsOutput.addColumn("uploadName",ColumnInfo.CY_COLINFO_STRING, 20);
	     
	     int row = dsOutput.appendRow();
	     dsOutput.setColumn(row, "empId", (String)pdtInfo.get("EMPLOYEE_ID") );
	     dsOutput.setColumn(row, "empName", (String)pdtInfo.get("NAME"));
	     dsOutput.setColumn(row, "deptName", (String)pdtInfo.get("DEPT_NAME") );
	     dsOutput.setColumn(row, "productCode", (String)pdtInfo.get("PRODUCT_CODE") );
	     dsOutput.setColumn(row, "productName", (String)pdtInfo.get("PRODUCT_NAME") );
	     dsOutput.setColumn(row, "itemCode", (String)pdtInfo.get("ITEM_CODE") );
	     dsOutput.setColumn(row, "category", (String)pdtInfo.get("CATEGORY_NAME") );
	     dsOutput.setColumn(row, "manufactureCode", (String)pdtInfo.get("MANUFACTURE_CODE") );
	     dsOutput.setColumn(row, "productNum", ((BigDecimal)pdtInfo.get("PRODUCT_NUM")).toString() );
	     dsOutput.setColumn(row, "standard", (String)pdtInfo.get("STANDARD") );
	     dsOutput.setColumn(row, "unitCode", (String)pdtInfo.get("UNIT_CODE") );
	     dsOutput.setColumn(row, "unitPrice", ((BigDecimal)pdtInfo.get("UNIT_PRICE")).toString() );
	     dsOutput.setColumn(row, "uploadName", (String)pdtInfo.get("FILENAME") );
	    
	     dsImg.addColumn("name", ColumnInfo.CY_COLINFO_STRING, 20);
	     dsImg.addBlobColumn("image");
	     
	     int imgRow = dsImg.appendRow();
	     dsImg.setColumn(row, "name", (String)pdtInfo.get("FILENAME"));
	     dsImg.setColumn(row, "image", pdt1000svcImpl.readFile((String)pdtInfo.get("FILENAME")));
	     
	     //set
	     out_dl.addDataset(dsOutput);
	     out_dl.addDataset(dsImg);
	    
	     //out.clearBuffer();
	     PlatformResponse pRes;
	     try {
	          pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
	          pRes.sendData(out_vl, out_dl);
	         
	     } catch (IOException e) {
	         
	          e.printStackTrace();
	     }
	    
	     log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
	                + "=======");
		
	}
	
	@RequestMapping("/insPDTInfo.do")
	public void insPDTInfo(HttpServletRequest request, HttpServletResponse response){
		
		log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

		PlatformRequest pReq = null;
		PlatformResponse pRes = null;
		
		try {
			pReq = new PlatformRequest(request, "utf-8");
			pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
			pReq.receiveData();
			
		} catch (IOException e1) {
			
			e1.printStackTrace();
		}
		VariableList in_vl = new VariableList();
		VariableList out_vl = new VariableList();
		DatasetList  in_dl = new DatasetList();
		DatasetList  out_dl = new DatasetList();
		
		in_vl = pReq.getVariableList();
		in_dl = pReq.getDatasetList();
		
		ErrorMsgVO errMsg = pdt1000svcImpl.doValidateCRUD(null, in_dl);
		
		if( errMsg.isErrExist() ){
			out_vl.addStr("ErrorCode", "-1");
			out_vl.addStr("ErrorMsg", errMsg.getErrMsg());
			
			try {
				pRes.sendData(out_vl, out_dl);
				return;
				
			} catch (IOException e) {
				
				e.printStackTrace();
			}
		}
				
		//get
		Dataset dsData = in_dl.getDataset("insData");
		Dataset dsImg = in_dl.getDataset("imgData");
		
		//TODO: logic
		upload(dsImg);
		ProductInfoVO vo = dataSetToBean(dsData);
		vo.setFilename(dsImg.getColumnAsString(0, "name"));
		
		pdt1000svcImpl.insPDTInfo(vo);
		
		//out.clearBuffer();
		out_vl.addStr("ErrorCode", "0");
		out_vl.addStr("ErrorMsg", "입력이 성공되었습니다.");
		
		try {
			pRes.sendData(out_vl, out_dl);
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

	}
	public Map<String, Object> parsingParaMap(Map<String, String[]> paraMap){
		Iterator<Entry<String, String[]>> it=paraMap.entrySet().iterator();
		Map<String, Object> map = new HashMap<String, Object>();
		
		while(it.hasNext()){
			Entry<String, String[]> entry = it.next();
			
			if(entry.getValue().length > 1){
				List<String> list= new ArrayList<String>();
				
				for (String str : entry.getValue()) {
					list.add(str);
				}
				
				map.put(entry.getKey(), list);
			}else{
				map.put(entry.getKey(), entry.getValue()[0]);
				
			}			
		}
		
		return map;
	}
	
	@RequestMapping("/doPDTMainView.do")
	public void doPDTMainView(HttpServletRequest request, HttpServletResponse response){
		
		log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

		PlatformRequest pReq = null;
		PlatformResponse pRes = null;
		
		try {
			pReq = new PlatformRequest(request, "utf-8");
			pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
			pReq.receiveData();
			
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		VariableList in_vl = new VariableList();
		VariableList out_vl = new VariableList();
		DatasetList  dl = new DatasetList();
		Map<String, Object> paraMap = new HashMap<String, Object>();
		
		
		in_vl = pReq.getVariableList();
		
		ErrorMsgVO errMsg = pdt1000svcImpl.doValidateMain(in_vl, null);
		
		if( errMsg.isErrExist() ){
			out_vl.addStr("ErrorCode", "-1");
			out_vl.addStr("ErrorMsg", errMsg.getErrMsg());
			
			try {
				pRes.sendData(out_vl, dl);
				
				return;
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
				
		String saleSearch1 = in_vl.getValueAsString("saleSearch1");
		String saleSearch2 = in_vl.getValueAsString("saleSearch2");
		String productName = in_vl.getValueAsString("productName");
		String start_sel_rowno = in_vl.getValueAsString("start_sel_rowno");
		String unit_sel_rownum = in_vl.getValueAsString("unit_sel_rownum");
		int start = Integer.parseInt(start_sel_rowno);
		int end = Integer.parseInt(unit_sel_rownum) - start + 1;
		
		if( saleSearch1 == null && saleSearch2 == null){
			Calendar now = Calendar.getInstance();
			
			saleSearch1 = ""+now.get(Calendar.YEAR)
					+( (now.get(Calendar.MONTH)+1)<10 ? "0"+(now.get(Calendar.MONTH)+1) : now.get(Calendar.MONTH)+1 )
					+"01";
			saleSearch2 = ""+now.get(Calendar.YEAR)
					+( (now.get(Calendar.MONTH)+1)<10 ? "0"+(now.get(Calendar.MONTH)+1) : now.get(Calendar.MONTH)+1 )
					+( now.get(Calendar.DATE)<10 ? "0"+now.get(Calendar.DATE) : now.get(Calendar.DATE) );
			
			out_vl.addStr("saleSearch1", "20140101");
			out_vl.addStr("saleSearch2", "20141201");
		}
		
		paraMap.put("saleSearch1", saleSearch1);
		paraMap.put("saleSearch2", saleSearch2);
		paraMap.put("productName", productName);
		paraMap.put("start", start);
		paraMap.put("end", end);
		
		Dataset ds = new Dataset("output");
		ds.addColumn("productCode",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("productName",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("itemCode",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("itemName",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("manufactureName",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("categoryName",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("standard",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("unitCode",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("unitPrice",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("employeeName",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("saleStime",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("saleEtime",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("productNum",ColumnInfo.CY_COLINFO_STRING, 20);
		ds.addColumn("rowno",ColumnInfo.CY_COLINFO_STRING, 20);
		
		//TODO: paging
		String page = "1";
		
		List<Map<String, Object>> list = pdt1000svcImpl.getProductInfoList(page, paraMap);
		
		for (Map<String, Object> map : list) {
			int row = ds.appendRow();
			
			Iterator<Entry<String, Object>> it = map.entrySet().iterator();
			
			while ( it.hasNext() ) {	
				Entry<String, Object> entry = it.next();
				
				ds.setColumn(row, entry.getKey(), (String)entry.getValue() );
				
			}
		}
		
		dl.addDataset(ds);
		
		
		//out.clearBuffer();
		out_vl.addStr("ErrorCode", "0");
		out_vl.addStr("ErrorMsg", "success");
		
		try {
			pRes.sendData(out_vl, dl);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

	}
	
	
	@RequestMapping("/getCategory.do")
	@ResponseBody
	public ResultVO getCategory(HttpServletRequest request){
		Logger log=Logger.getLogger(this.getClass());
		log.debug("getCategory "+request.getParameter("itemName"));
		
		ResultVO vo= new ResultVO();
	
		String codeName = pdt1000svcImpl.getCategoryName(request.getParameter("itemName"));
		vo.setStr(codeName);
		
		return vo;
	}
	
	@RequestMapping("/codeZip.do")
	@ResponseBody
	public void codeZip(HttpServletRequest request,HttpServletResponse response){
		
		log.debug( "=======start: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");
		
		
		VariableList in_vl = new VariableList();
		VariableList out_vl = new VariableList();
		DatasetList  dl = new DatasetList();
		Map<String, Object> paraMap = new HashMap<String, Object>();
				
		Map<String, List<EMP1000VO>> codeMap = pdt1000svcImpl.getCodeZipList();
		
		List<EMP1000VO> categoryl = codeMap.get("CATEGORY");
		List<EMP1000VO> manufacturel = codeMap.get("MANUFACTURE");
		List<EMP1000VO> unitl = codeMap.get("UNIT");
		
		Dataset dsCategory = new Dataset("category");
		Dataset dsManufactureName = new Dataset("manufactureName");
		Dataset dsUnitCode = new Dataset("unitCode");
		
		dsCategory.addColumn("codeDetail",ColumnInfo.CY_COLINFO_STRING, 20);
		dsCategory.addColumn("codeName",ColumnInfo.CY_COLINFO_STRING, 20);
		dsManufactureName.addColumn("codeDetail",ColumnInfo.CY_COLINFO_STRING, 20);
		dsManufactureName.addColumn("codeName",ColumnInfo.CY_COLINFO_STRING, 20);
		dsUnitCode.addColumn("codeDetail",ColumnInfo.CY_COLINFO_STRING, 20);
		dsUnitCode.addColumn("codeName",ColumnInfo.CY_COLINFO_STRING, 20);
		
		for (EMP1000VO emp1000vo : categoryl) {
			int row = dsCategory.appendRow();
			
			dsCategory.setColumn(row, "codeDetail", emp1000vo.getCode_detail());
			dsCategory.setColumn(row, "codeName", emp1000vo.getCode_name());
		}
		for (EMP1000VO emp1000vo : manufacturel) {
			int row = dsManufactureName.appendRow();
			
			dsManufactureName.setColumn(row, "codeDetail", emp1000vo.getCode_detail());
			dsManufactureName.setColumn(row, "codeName", emp1000vo.getCode_name());
		}
		for (EMP1000VO emp1000vo : unitl) {
			int row = dsUnitCode.appendRow();
			
			dsUnitCode.setColumn(row, "codeDetail", emp1000vo.getCode_detail());
			dsUnitCode.setColumn(row, "codeName", emp1000vo.getCode_name());
		}
		
		List<ItemInfoVO> productCodel = pdt1000svcImpl.getItemNameList();
		Dataset dsProductCode = new Dataset("productCode");
		
		dsProductCode.addColumn("codeDetail",ColumnInfo.CY_COLINFO_STRING, 20);
		dsProductCode.addColumn("codeName",ColumnInfo.CY_COLINFO_STRING, 20);
		dsProductCode.addColumn("categoryName",ColumnInfo.CY_COLINFO_STRING, 20);
		
		for (ItemInfoVO itemInfoVO : productCodel) {
			int row = dsProductCode.appendRow();
			
			dsProductCode.setColumn(row, "codeDetail", itemInfoVO.getItemCode());
			dsProductCode.setColumn(row, "codeName", itemInfoVO.getItemName());
			dsProductCode.setColumn(row, "categoryName", itemInfoVO.getCategoryCode());
		}
		
		dl.addDataset(dsCategory);
		dl.addDataset(dsManufactureName);
		dl.addDataset(dsUnitCode);
		dl.addDataset(dsProductCode);
		
		//out.clearBuffer();
		PlatformResponse pRes;
		try {
			pRes = new PlatformResponse(response, PlatformRequest.XML, "utf-8");
			pRes.sendData(out_vl, dl);
			
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
		log.debug( "=======end: "+ this.getClass().getName()+ "."+ new Exception().getStackTrace()[0].getMethodName()
		           + "=======");

	}
	
	ProductInfoVO dataSetToBean(Dataset ds){
		ProductInfoVO vo = new ProductInfoVO();
		
		vo.setEmployeeName(ds.getColumnAsString(0, "empId"));
		vo.setProductCode(ds.getColumnAsString(0, "productCode"));
		vo.setProductName(ds.getColumnAsString(0, "productName"));
		vo.setItemCode(ds.getColumnAsString(0, "itemCode"));
		vo.setManufactureCode(ds.getColumnAsString(0, "manufactureCode"));
		vo.setStandard(ds.getColumnAsString(0, "standard"));
		vo.setUnitCode(ds.getColumnAsString(0, "unitCode"));
		vo.setUnitPrice(new BigDecimal(ds.getColumnAsString(0, "unitPrice")));
		
		return vo;
		
	}
	
	public void upload(Dataset ds){
		  StringBuffer name=new StringBuffer(); 
		  
		  name.append("C:\\TB\\WORKSHOP\\workspace\\tbworkshop2\\WebContent\\upload\\");  
		  name.append(ds.getColumnAsString(0, "name"));

		  byte[] file=ds.getColumnAsByteArray(0, "image");
		  FileOutputStream fileOut = null;
		  BufferedOutputStream bufferedOut = null;
		  
		  try {
			
			fileOut = new FileOutputStream(new File(name.toString()));
			bufferedOut=new BufferedOutputStream(fileOut);
			bufferedOut.write(file);
			bufferedOut.flush();
			bufferedOut.close(); 
			fileOut.close();
			
		  } catch (Exception e) {
			
		 	e.printStackTrace();
		  }
		  
	}
	
}
